/***************************************************************
|	File:		Graphics.h
|	Author:		Michael Mozdzierz
|	Date:		05/24/2014
|
***************************************************************/

#pragma once

#include <d3d11.h>
#include <DirectXMath.h>

#define D3D_INIT_FAILURE 0x01
#define COMPILE_SHADER_FAILURE 0x02
#define D3D_BUFFER_FAILURE 0x04

using namespace DirectX;

struct Color;
struct VertexPositionColor;
union Matrix;

class Graphics
{
	IDXGISwapChain* swapchain = nullptr;             // the pointer to the swap chain interface
	ID3D11Device* device = nullptr;                     // the pointer to our Direct3D device interface
	ID3D11DeviceContext* device_context = nullptr;           // the pointer to our Direct3D device context

	ID3D11RenderTargetView* back_buffer;

	HWND hwnd;

	ID3D11InputLayout* buffer_layout = nullptr;

	ID3D11Buffer* constantBuffer = nullptr;
	// shaders

	ID3D11VertexShader* vertex_shader = nullptr;
	ID3D11PixelShader* pixel_shader = nullptr;


	/////////////////////////<Private ctor/dor>///////////////////////////////////////////////////

	Graphics(void);
	~Graphics(void);

	/////////////////////////<Private functions>///////////////////////////////////////////////////

	int InitPipeline(void);
public:
	int Inilitize(HWND);

	void Clear(Color& color);

	void Present(void);
	void Dispose(void);
	
	void SetVertexShader(const wchar_t* filename);
	void SetPixelShader(const wchar_t* filename);

	void Begin(Color& clearColor);
	void End(void);

	void DrawVertecies(VertexPositionColor* vBuffer, unsigned int length, Matrix* world = nullptr, Matrix* view = nullptr, Matrix* projection = nullptr);

	/////////////////////////<Public Types>///////////////////////////////////////////////////

	struct ConstantBufferData
	{
		XMFLOAT4X4 World;
		XMFLOAT4X4 View;
		XMFLOAT4X4 Projection;
	} cBufferData;


	/////////////////////////<Singleton accessor>///////////////////////////////////////////////////

	static Graphics* GetInstance(void);
};